/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/settleService.ts" />
/// <reference path="../src/tms.ts" />

describe('getSettleList',() => {
    var injector:ng.auto.IInjectorService;
    var service:ISettleService;

    beforeEach(() => {
        injector = angular.injector(['ng','tms']);
        service = injector.get<ISettleService>('settleService');
    });

    //常规无条件获取
    it('get settle list normal',(done) => {
        service.getList(null, null, null, null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

     //获取企业公司编号包含1的结算方列表
    it('get settle list by enterpriseid \'1\'',(done) => {
        service.getList("1",null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("1||||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取结算单位名称包含 汽车零部件有限公司 的结算方列表
    it('get settle list by name \'汽车零部件有限公司\'',(done) => {
        service.getList(null,"汽车零部件有限公司",null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("|汽车零部件有限公司|||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取联系人含有'李大'的结算方列表
    it('get settle list by contactman \'李大\'',(done) =>{
        service.getList(null,null,"李大",null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("||李大||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取禁用的结算方列表
    it('get settle list by disabled  ',(done) => {
        service.getList(null,null,null,false,0,10).then((res) => {
            expect(res.data.total).toBe(10);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("|||false|0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取企业公司编号包含1，结算单位名称包含公司，联系人包含李， 禁用的结算方列表
    it('get settle list by enterpriseid \'1\' and name \'公司\' and contactman \'李\' and  disabled  ',(done) => {
        service.getList('1','公司','李',false,0,10).then((res) => {
             expect(res.data.total).toBe(10);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("1|公司|李|false|0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取结算方详情
    it("get detail",(done) => {
        service.getDetail("1").then((res) => {
            expect(res.data.enterpriseCompanyId).toBe("1");
            expect(res.data.name).toBe("公司");
            expect(res.data.phoneNumber).toBe("18352868444");
            expect(res.data.isEnable).toBe(true);
            expect(res.data.contactMan).toBe("李");
            expect(res.data.remarks).toBe("结算方备注");
            expect(res.data.extData).toBe("1");
            done();
        },(err) => {
            done.fail(err);
        });
    });


    //编辑结算方
    it('edit settle ',(done)=>{
        service.edit("3","1","大学","李","1380",false,"测试编辑结算方").then((res)=>{
            expect(res.data.extData).toBe("3|1|大学|李|1380|false|测试编辑结算方");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //添加结算方
    it('add settle ',(done)=>{
        service.add("2","结算方",'一一','13800107782',true,"33").then((res)=>{
            expect(res.data.extData).toBe("2|结算方|一一|13800107782|true|33");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //删除结算方
    it('delete settle ',(done)=>{
        service.delete("1").then((res)=>{
            expect(res.data.extData).toBe("1");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

      
});